﻿#define _CRT_SECURE_NO_WARNINGS
//作者：宋安康

//strncat
#include<stdio.h>
//int main()
//{
//	char arr1[20] = "hello\0xxxxxxx";
//	char arr2[] = "world";
//	strncat(arr1, arr2, 7);  
//	return	0;
//}

//strncmp
//int main()
//{
//	char arr1[] = "abcdef";
//	char arr2[] = "abcd";
//	int ret =strncmp(arr1, arr2, 5);
//	printf("%d\n",ret);
//	return	0;
//}

//strstr 的使用和模拟实现
// char * strstr ( const char * str1, const char * str2);
//strstr 的模拟实现

#include<assert.h>
char* my_strstr(const char* str1,const char* str2) //暴力求解
//查询KMP算法----b站大博哥
{
	char* s1 = NULL;
	char* s2 = NULL;
	assert(str1&&str2);

	const char* cur = str1;   //记录起始位置
	while (cur!= '\0')
	{
		s1 = cur;
		s2 = str2;
		if (*str2 == '\0')
		{
			return ((char*)str1);
		}
		while (*s1 && *s2 && *s1 == *s2)
		{
			s1++;
			s2++;
		}
		if (s2 == '\0')
		{
			return ((char*)cur);
		}
		cur++;
	}
	return NULL;
	

}
int main()
{
	char arr1[] = "abcdef";
	char arr2[] = "abcdef";
	char* ret = my_strstr(arr1,arr2);
	if (ret == NULL)
	{
		printf("找不到");
	}
	else
	{
		printf("%s\n",ret);
	}
	
	
	return	0;
}